<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Agent extends Model
{
    use HasFactory;
    protected $fillable = ["name","agent_level_id","mob","realname","province","city","country","address","username","password","cash","status"];
    protected $dateFormat = 'U';

    public function getStatusAttribute($value) {
        return $value == 2 ? '冻结' : '正常';
    }

    public function getAgentLevelIdAttribute($value) {
        return $value == 2 ? '二级代理' : '一级代理';
    }

    public function setCashAttribute($value) {
        $this->attributes['cash'] = $value * 100;
    }

    public function getCashAttribute($value) {
        return number_format($value/100, 2);
    }

    public function cashes() {
        return $this->hasMany(Cash::class);
    }

}
